package com.coldchain.admin.resoure.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.coldchain.admin.resoure.entity.Resource;
import com.coldchain.admin.resoure.mapper.ResourceMapper;
import com.coldchain.admin.resoure.service.IResourceService;
import com.coldchain.common.exception.base.BusinessException;
import com.coldchain.common.util.TreeUtil;
import com.fangliai.core.exception.BaseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 资源表 服务实现类
 * </p>
 *
 * @author fangliai
 * @since 2018-08-28
 */
@Service
public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource> implements IResourceService {
    private static final Logger log= LoggerFactory.getLogger(ResourceServiceImpl.class);

    @Override
    public List<Resource> listAllBySysModel(String sysmodel)throws BaseException {
        try {
            QueryWrapper wrapper=new QueryWrapper();
            wrapper.eq("sysmodel",sysmodel.toUpperCase());
            List<Resource> resources=super.list(wrapper);
            return  new TreeUtil<Resource>().bulid(resources,0,null);
        }catch (Exception e){
            log.error("获取资源信息失败,error【{}】",e.getMessage());
            throw  new BusinessException("服务异常");
        }

    }
}
